class BillPageModel {
  final String? expenditure;
  final bool? hasNext;
  final bool? haxNextMonth;
  final String? income;
  final List<BillItemModel>? list;
  final int? month;
  final int? year;

  BillPageModel({
    this.expenditure,
    this.hasNext,
    this.haxNextMonth,
    this.income,
    this.list,
    this.month,
    this.year,
  });

  factory BillPageModel.fromJson(Map<String, dynamic>? json) => BillPageModel(
        expenditure: json?["expenditure"],
        hasNext: json?["hasNext"],
        haxNextMonth: json?["haxNextMonth"],
        income: json?["income"],
        list: json?["list"] == null ? null : List<BillItemModel>.from(json?["list"].map((x) => BillItemModel.fromJson(x))),
        month: json?["month"],
        year: json?["year"],
      );

  Map<String, dynamic> toJson() => {
        "expenditure": expenditure,
        "hasNext": hasNext,
        "haxNextMonth": haxNextMonth,
        "income": income,
        "list": List<dynamic>.from(list?.map((x) => x.toJson()) ?? []),
        "month": month,
        "year": year,
      };
}

class BillItemModel {
  final int? actualAmount;
  final int? actualIntegral;
  final int? agentLevel;
  final int? amount;
  final String? channelType;
  final String? createdAt;
  final int? currencyType;
  final String? desc;
  final String? discBindAt;
  final String? districtCode;
  final int? downloadCount;
  final int? fruitCoin;
  final int? fruitCoinBalance;
  final String? id;
  final int? integral;
  final bool? isDirect;
  final String? money;
  final int? performance;
  final String? productId;
  final String? promSeqe;
  final String? purchaseOrder;
  final String? realAmount;
  final String? realIntegral;
  final int? rechargeId;
  final RechargeUser? rechargeUser;
  final String? sysType;
  final int? tax;
  final int? taxAmount;
  final String? tranType;
  final int? tranTypeInt;
  final int? uid;
  final String? uniqueOrder;
  final int? vipLevel;
  final String? wlRealAmount;

  String unit() {
    if (tranTypeInt == 80 || tranTypeInt == 89 || tranTypeInt == 116) {
      return '积分';
    }
    if (tranTypeInt == 103 || tranTypeInt == 104 || tranTypeInt == 109 || tranTypeInt == 110 || tranTypeInt == 111) {
      return "次";
    }
    return "金币";
  }

  int realCount() {
    if (actualAmount == 0 && actualIntegral != 0) {
      return actualIntegral ?? 0;
    }
    if (actualAmount != 0 && actualIntegral == 0) {
      return actualAmount ?? 0;
    }

    return 0;
  }

  BillItemModel({
    this.actualAmount,
    this.actualIntegral,
    this.agentLevel,
    this.amount,
    this.channelType,
    this.createdAt,
    this.currencyType,
    this.desc,
    this.discBindAt,
    this.districtCode,
    this.downloadCount,
    this.fruitCoin,
    this.fruitCoinBalance,
    this.id,
    this.integral,
    this.isDirect,
    this.money,
    this.performance,
    this.productId,
    this.promSeqe,
    this.purchaseOrder,
    this.realAmount,
    this.realIntegral,
    this.rechargeId,
    this.rechargeUser,
    this.sysType,
    this.tax,
    this.taxAmount,
    this.tranType,
    this.tranTypeInt,
    this.uid,
    this.uniqueOrder,
    this.vipLevel,
    this.wlRealAmount,
  });

  factory BillItemModel.fromJson(Map<String, dynamic> json) => BillItemModel(
        actualAmount: json["actualAmount"],
        actualIntegral: json["actualIntegral"],
        agentLevel: json["agentLevel"],
        amount: json["amount"],
        channelType: json["channelType"],
        createdAt: json["createdAt"],
        currencyType: json["currencyType"],
        desc: json["desc"],
        discBindAt: json["discBindAt"],
        districtCode: json["districtCode"],
        downloadCount: json["downloadCount"],
        fruitCoin: json["fruitCoin"],
        fruitCoinBalance: json["fruitCoinBalance"],
        id: json["id"],
        integral: json["integral"],
        isDirect: json["isDirect"],
        money: json["money"],
        performance: json["performance"],
        productId: json["productID"],
        promSeqe: json["promSeqe"],
        purchaseOrder: json["purchaseOrder"],
        realAmount: json["realAmount"],
        realIntegral: json["realIntegral"],
        rechargeId: json["rechargeId"],
        rechargeUser: RechargeUser.fromJson(json["rechargeUser"] ?? {}),
        sysType: json["sysType"],
        tax: json["tax"],
        taxAmount: json["taxAmount"],
        tranType: json["tranType"],
        tranTypeInt: json["tranTypeInt"],
        uid: json["uid"],
        uniqueOrder: json["uniqueOrder"],
        vipLevel: json["vipLevel"],
        wlRealAmount: json["wlRealAmount"],
      );

  Map<String, dynamic> toJson() => {
        "actualAmount": actualAmount,
        "actualIntegral": actualIntegral,
        "agentLevel": agentLevel,
        "amount": amount,
        "channelType": channelType,
        "createdAt": createdAt,
        "currencyType": currencyType,
        "desc": desc,
        "discBindAt": discBindAt,
        "districtCode": districtCode,
        "downloadCount": downloadCount,
        "fruitCoin": fruitCoin,
        "fruitCoinBalance": fruitCoinBalance,
        "id": id,
        "integral": integral,
        "isDirect": isDirect,
        "money": money,
        "performance": performance,
        "productID": productId,
        "promSeqe": promSeqe,
        "purchaseOrder": purchaseOrder,
        "realAmount": realAmount,
        "realIntegral": realIntegral,
        "rechargeId": rechargeId,
        "rechargeUser": rechargeUser?.toJson(),
        "sysType": sysType,
        "tax": tax,
        "taxAmount": taxAmount,
        "tranType": tranType,
        "tranTypeInt": tranTypeInt,
        "uid": uid,
        "uniqueOrder": uniqueOrder,
        "vipLevel": vipLevel,
        "wlRealAmount": wlRealAmount,
      };
}

class RechargeUser {
  final String? name;
  final String? portrait;
  final int? uid;

  RechargeUser({
    this.name,
    this.portrait,
    this.uid,
  });

  factory RechargeUser.fromJson(Map<String, dynamic> json) => RechargeUser(
        name: json["name"],
        portrait: json["portrait"],
        uid: json["uid"],
      );

  Map<String, dynamic> toJson() => {
        "name": name,
        "portrait": portrait,
        "uid": uid,
      };
}
